home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0056_Executing a file from Delphi.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  690 b   |  22 lines

  1.  
  2. The first point I would make is that you went to an awful lot of trouble
  3. to implement the WinExec API call...  cleaner code would look like:
  4.  
  5. begin
  6.   winexec('C:\Program.exe', SW_SHOWNORMAL);
  7. end;
  8.  
  9. Delphi automatically treats this as a null-terminated string (like c).  As
  10. to the answer to your question.  WinExec returns a handle to the
  11. task.  Simply do the following:
  12.  
  13. procedure SomeProc;
  14. var
  15.   ProgramHandle : THandle;
  16. begin
  17.   ProgramHandle := WinExec('C:\Program.exe', SW_SHOWNORMAL);
  18.   while GetModuleusage(ProgramHandle) <> 0 do application.processmessages;
  19.   {The above line will loop until the program terminates}
  20.   {continue on with program below here}
  21. end;
  22.